using System;
using Microsoft.SPOT;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer;
using Gadgeteer.Interfaces;

namespace Dairy_Town
{
    public class Console
    {
        private GTM.Seeed.OledDisplay display = null;
        private static Console instance;

        static private uint printY = 0;

        private Console() { }

        internal static void AttachDisplay(GTM.Seeed.OledDisplay oledDisplay)
        {
            if (instance == null)
                instance = new Console();
            
            instance.display = oledDisplay;
        }

        /// <summary>
        /// Displays given text on OledDisplay and Console output
        /// </summary>
        /// <param name="text">String to display</param>
        public static void Display(string text)
        {
            Debug.Print(text);

            if (instance == null)
                instance = new Console();

            if (printY > 110) // If the top of line exceeds bottom of Oled screen, start from the top and clear current screen
            {
                printY = 0;
                instance.display.SimpleGraphics.Clear();
            }

            instance.display.SimpleGraphics.DisplayText(text, Resources.GetFont(Resources.FontResources.small), GT.Color.Red, 0, printY);
            
            printY += 10;
        }
    }
}
